# encoding: utf-8
from flask_marshmallow import base_fields
from app.modules.common.schemas import BaseSchema, ModelSchema
from .models import ProdSchemaDefine, ProdTableDefine, ProdTableInit, ProdTableExport, ProdTableClean, \
    ProdTableCheckRows


class SchemaBaseSchema(ModelSchema):
    class Meta:
        model = ProdSchemaDefine
        fields = (
            'id',
            'table_schema',
            'is_ignore',
            'schema_owner',
            'remark',
        )


class ExportBaseSchema(ModelSchema):
    class Meta:
        model = ProdTableExport
        fields = (
            'id',
            'table_schema',
            'table_name',
            'env_type',
            'script',
            'remark',
            'created',
            'createdby',
            'updated',
            'updatedby',
        )


class CleanBaseSchema(ModelSchema):
    class Meta:
        model = ProdTableClean
        fields = (
            'id',
            'table_schema',
            'table_name',
            'script',
            'remark',
            'sort',
            'is_active',
            'created',
            'createdby',
            'updated',
            'updatedby',
        )


class TableBaseSchema(ModelSchema):
    class Meta:
        model = ProdTableDefine
        fields = (
            'id',
            'table_schema',
            'table_name',
            'is_check_rows',
            'is_need_clean',
        )


class CheckRowBaseSchema(ModelSchema):
    class Meta:
        model = ProdTableCheckRows
        fields = (
            'id',
            'table_schema',
            'table_name',
            'this_rows',
            'checked_rows',
            'checked_date',
            'checkedby',
            'remark',
        )


class ViewBaseSchema(ModelSchema):
    class Meta:
        fields = (
            'id',
            'table_schema',
            'table_name',
            'is_check_rows',
            'is_need_clean',
            'manager',
            'purpose',
            'export_script',
            'clean_script',
            'check_rows',
        )


class InitBaseSchema(ModelSchema):
    class Meta:
        model = ProdTableInit
        fields = (
            'id',
            'table_schema',
            'table_schema_instance',
            'env_type',
            'script',
            'remark',
            'is_active',
            'created',
            'createdby',
            'updated',
            'updatedby',
        )


class SchemaListSchema(BaseSchema):
    data = base_fields.Nested(
        SchemaBaseSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )


class TableListSchema(BaseSchema):
    data = base_fields.Nested(
        TableBaseSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )


class ViewListSchema(BaseSchema):
    data = base_fields.Nested(
        ViewBaseSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )


class InitListSchema(BaseSchema):
    data = base_fields.Nested(
        InitBaseSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )


class ExportListSchema(BaseSchema):
    data = base_fields.Nested(
        ExportBaseSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )


class CleanListSchema(BaseSchema):
    data = base_fields.Nested(
        CleanBaseSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )


class CheckRowSchema(BaseSchema):
    data = base_fields.Nested(
        CheckRowBaseSchema,
        many = False
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )
